package cn.javacc.system.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.javacc.system.dao.UserDao;
import cn.javacc.system.domain.User;
import cn.javacc.util.Status;

@Service
public class UserService {
	@Inject
	private UserDao userDao;

	public User getUserById(Long id) {
		User user = this.userDao.get(id);
		if (user != null && user.getStatus() == Status.NORMAL) {
			return user;
		}
		return null;
	}

	public List<User> listUsers(int offset, int fetchSize) {
		return this.userDao.findAll(offset, fetchSize);
	}

	public int getUserTotalSize() {
		return this.userDao.getTotalSize();
	}

	@Transactional
	public void saveUser(User user) {
		this.userDao.save(user);
	}

	@Transactional
	public void updateUser(User user) {
		this.userDao.update(user);
	}

	@Transactional
	public void deleteUser(Long id) {
		this.userDao.delete(id);
	}
}
